package com.xigua._数学;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/2/1115:59
 */
public class _1041_困于环中的机器人 {

    public static void main(String[] args) {

    }

    public boolean isRobotBounded(String instructions) {
        instructions = instructions+instructions+instructions+instructions;
        int x=0,y=0; int direction = 1;
        char[] chars = instructions.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (  chars[i] == 'L'){
                if (direction == 1){
                    direction = 4;
                } else {
                    direction -=1;
                }
            }
            else if (  chars[i] == 'R'){
                if (direction == 4){
                    direction = 1;
                }
                else {
                    direction +=1;
                }
            }
            else if (direction == 1 && chars[i] == 'G'){
                y +=1;
            }
            else if (direction == 2 && chars[i] == 'G') {x +=1;}
            else if (direction == 3 && chars[i] == 'G') {y -=1;}
            else if (direction == 4 && chars[i] == 'G') {x -=1; }
        }
        return x ==0 && y==0;
    }
}
